package l1j.server.server.model;

import static l1j.server.server.model.skill.L1SkillId.WATER_LIFE;
import static l1j.server.server.model.skill.L1SkillId.POLLUTE_WATER;

import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_ServerMessage;
import l1j.server.server.serverpackets.S_SkillIconWaterLife;
import l1j.server.server.serverpackets.S_SkillSound;

public class HealGuard extends TimerTask {
   private static Logger _log = Logger.getLogger(HealGuard.class.getName());

   private final L1PcInstance Active_pc;

   public HealGuard(L1PcInstance pc) {
      Active_pc = pc;
   }

   @Override
   public void run() {
      try {
         if (Active_pc.isDead()) {
            return;
         }
         Active_pc.sendPackets(new S_SkillSound(Active_pc.getId(), 2245));
         Active_pc.broadcastPacket(new S_SkillSound(Active_pc.getId(), 2245));
      } catch (Throwable e) {
         _log.log(Level.WARNING, e.getLocalizedMessage(), e);
      }
   }
   
   public void HealingEffect(L1PcInstance _pc, int rnd) {
      int heal_hp = rnd + 72;
      
      if (_pc.hasSkillEffect(WATER_LIFE)) {
         heal_hp *= 2;
         _pc.killSkillEffectTimer(WATER_LIFE);
         _pc.sendPackets(new S_SkillIconWaterLife());
      }
      if (_pc.hasSkillEffect(POLLUTE_WATER)) {
         heal_hp /= 2;         
      }
      
      _pc.setCurrentHp((heal_hp + _pc.getCurrentHp()));
      _pc.sendPackets(new S_SkillSound(Active_pc.getId(), 2187));
      _pc.broadcastPacket(new S_SkillSound(Active_pc.getId(), 2187));
      _pc.sendPackets(new S_ServerMessage(77));
   }
}